#!/bin/sh
# show status of org-pomodoro in a progress bar.
# tied to mpd, toggles on when working, off on break

calc() {
    echo "$*" | bc -l
}

time_offset_percent() {
    duration="$1" # minutes

    interval="$(calc ${duration} \* 60)"

    time_left="$(elisp '(format-time-string "%s" (org-pomodoro-remaining-seconds))' | tr -d '"')"
    percent="$(calc "((${interval} - ${time_left}) / ${interval}) * 100" | sed 's/\..*//')"

    percent=${percent:-0}
    echo "${percent}"
}

progress() {
    mkb "$(time_offset_percent "$1")" 10 ◼ ◻ ◻
}

get_length() {
    elisp "org-pomodoro-${@}length"
}

pomodoro_state="$(elisp org-pomodoro-state)"

case ${pomodoro_state} in
    :short-break)
        echo "Break $(progress $(get_length short-break-))"
        ;;

    :long-break)
        echo "Long break $(progress $(get_length long-break-))"
        ;;

    :pomodoro)
        task="$(elisp org-clock-current-task | tr -d '"')"
        echo "${task} $(progress $(get_length))"
        ;;

    :none)
        echo "Pick a task!"
        ;;

    *)
        echo "No Task!"
        ;;
esac
